from django.db import models
from django.contrib.auth.models import Group

from rest_framework import permissions
# Create your models here.

# class Group(models.Model):
#     id = models.AutoField(primary_key=True)
#     groupname = models.CharField(max_length=16,null=True,blank=True)
#
#     def __str__(self):
#         return self.groupname

class Host(models.Model):
    id =  models.AutoField(primary_key=True)
    hostname = models.CharField(max_length=16,null=True,blank=True)
    ip = models.GenericIPAddressField(null=True,blank=True)
    port = models.IntegerField(null=True,blank=True)
    username = models.CharField(max_length=16,null=True,blank=True)
    password = models.CharField(max_length=16,null=True,blank=True)
    ssh_key = models.TextField(max_length=30,null=True,blank=True)
    mod_date = models.DateTimeField('最后修改日期', auto_now = True)
    groups = models.ManyToManyField(Group,blank=True)

    def __str__(self):
        return self.hostname

class GroupVar(models.Model):
    id = models.AutoField(primary_key=True)
    key = models.CharField(max_length=16)
    value = models.CharField(max_length=16)
    group = models.ForeignKey(Group,related_name='groupvars',on_delete=models.CASCADE,default='')
    def __str__(self):
        return self.key

class Tag(models.Model):
    id = models.AutoField(primary_key=True)
    usage = models.ManyToManyField(Host)
    name    = models.CharField(max_length=50)
    def __str__(self):
        return str("Name:"+self.Name)


